package com.seesman.application.maintenance.common.gui;

import static com.seesman.application.maintenance.common.gui.utilities.MessageFormatUtil.format;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import com.seesman.application.maintenance.common.gui.utilities.FrameDetailsUtil.AboutBoxLabel;

public class SeesmanAboutBox extends JDialog implements ActionListener {
	
	private static final long serialVersionUID = -3168733420307783857L;

	private static final String resourceBundle = "ApplicationResource";
	
	private JButton closeButton;
	
	public SeesmanAboutBox(JFrame frame){
		initComponents();
		setLocationRelativeTo(frame);
		setModal(true);
		setVisible(true);
	}
		
	private void initComponents(){
		
		closeButton = new JButton();
		
		JLabel appTitleLabel = new JLabel();
		JLabel appDescLabel = new JLabel();
		JLabel appVersionLabel = new JLabel();
		JLabel versionLabel = new JLabel();
		JLabel appHomePageLabel = new JLabel();
		JLabel homePageLabel = new JLabel();
		JLabel imageLabel = new JLabel();
		JTextArea txtDesc = new JTextArea();
		
		setTitle(format(resourceBundle, "title.AboutBox"));
		setModal(true);
		setName("");
		setResizable(false);
				
		appTitleLabel.setText(format(resourceBundle, "label.Title"));
		appTitleLabel.setName(AboutBoxLabel.TITLE_LABEL.toString());
		
		appDescLabel.setText(format(resourceBundle, "label.desc.Title"));
		appDescLabel.setName(AboutBoxLabel.TITLE_DESC.toString());			
		
		appVersionLabel.setText(format(resourceBundle, "label.Version"));
		appVersionLabel.setName(AboutBoxLabel.VERSION_LABEL.toString());
		
		versionLabel.setText(format(resourceBundle, "label.desc.Version"));
		versionLabel.setName(AboutBoxLabel.VERSION_DESC.toString());
		
		appHomePageLabel.setText(format(resourceBundle, "label.HomePage"));
		appHomePageLabel.setName(AboutBoxLabel.HOMEPAGE_LABEL.toString());		
		
		homePageLabel.setText(format(resourceBundle, "label.desc.HomePage"));
		homePageLabel.setName(AboutBoxLabel.HOMEPAGE_DESC.toString());
		
		imageLabel.setIcon(new ImageIcon("icon-image/save.gif"));
		imageLabel.setName("imageLabel");
		
		closeButton.setText(format(resourceBundle, "button.Close"));
		closeButton.addActionListener(this);
		
		GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
            	.addGap(10, 10, 10)
            	.addComponent(imageLabel)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(appVersionLabel)                            
                            .addComponent(appHomePageLabel))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(versionLabel)
                            .addComponent(homePageLabel)))
                    .addComponent(appTitleLabel, GroupLayout.Alignment.LEADING)
                    .addComponent(appDescLabel, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
                    .addComponent(closeButton,GroupLayout.Alignment.CENTER))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(imageLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(appTitleLabel)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(appDescLabel)
                .addGap(19, 19, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(appVersionLabel)
                    .addComponent(versionLabel))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(appHomePageLabel)
                    .addComponent(homePageLabel))
                .addGap(19, 19, Short.MAX_VALUE)                
                .addComponent(closeButton)
                .addContainerGap())
        );
		
		pack();
	}

	public void actionPerformed(ActionEvent event) {

		Object source = event.getSource();
		
		if (source == closeButton){	
            setVisible(false);
		}
		
	}
}
